package com.kmxd.ams.core.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.kmxd.ams.core.common.constant.ErrorCode;
import com.kmxd.ams.core.exception.BizException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * 鉴定枚举
 *
 * @author nickbi
 */
@Getter
@AllArgsConstructor
public enum ArchiveUsingEnum {
  /** 协助查询 */
  ASSISTANCE_INQUIRY(1, "协助查询"),
  ARCH_PUSH(2, "档案推送"),
  AUTH(3, "赋权登记"),
  REGISTER_TO_BORROW(4, "登记借阅"),
  REGISTRATION_RETURN(5, "登记归还"),
  COPY_OUT(5, "复制外发"),
  EXCEPTION_REGISTRATION(5, "归还异常登记"),
  ;

  private Integer code;
  private String desc;

  public static ArchiveUsingEnum convert(Integer type) {
    return Arrays.stream(values())
        .filter(x -> x.code.equals(type))
        .findAny()
        .orElseThrow(() -> BizException.instance(ErrorCode.NOT_FOUND, "未找到档案状态：" + type));
  }

  @JsonCreator
  public static ArchiveUsingEnum getValue(Integer type) {
    return Arrays.stream(values()).filter(x -> Objects.equals(x.code, type)).findAny().orElse(null);
  }
}
